//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web;
using CommunityServer.Components;
//using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Components
{
	/// <summary>
	/// Summary description for ThreadNavigationHandler.
	/// </summary>
	public class ThreadNavigationHandler : IHttpHandler
	{
		public ThreadNavigationHandler()
		{
			//
			// TODO: Add constructor logic here
			//
		}
		#region IHttpHandler Members

		public void ProcessRequest(HttpContext context)
		{
			CSContext csContext = CSContext.Current;

			ThreadNavigationType navType = (ThreadNavigationType)Enum.Parse(typeof(ThreadNavigationType), context.Request["NavType"]);

			if (csContext.PostID != 0)
			{
				switch (navType)
				{
					case ThreadNavigationType.Next:
						context.Response.Redirect(Globals.GetSiteUrls().Post(Threads.GetNextThreadID(csContext.PostID)));
						break;
					case ThreadNavigationType.Previous:
						context.Response.Redirect(Globals.GetSiteUrls().Post(Threads.GetPrevThreadID(csContext.PostID)));
						break;
				}
			}

			throw new CSException(CSExceptionType.UnknownError);
		}

		public bool IsReusable
		{
			get { return false; }
		}

		#endregion
	}
}
